#测试我的练习
import time
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

from common.Untils import WJDriver
from selenium.webdriver.common.by import By

class WJExercise:
    url = ""
    driver = ""

    def __init__(self):
        #WJLogin.WJLogin().LoginSuccess()
        self.url = "http://8.155.1.153:8081/exercise"
        self.driver = WJDriver.driver
        self.driver.get(self.url)
        WJDriver.Login()
        #点击我的练习
        self.driver.find_element(By.CSS_SELECTOR,"#sk-layout > div > div > section > aside > div > div:nth-child(1) > ul > li:nth-child(3)").click()
    # 进行页面元素的查找检查
    def TestByExercise(self):
        sleep(1)
        #检查我的练习
        text=self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[1]/div/span").text
        assert text=="我的练习"
        print("我的练习页面：我的练习")
        sleep(1)
        #检查高数
        text=self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[3]/div").text
        assert text == "高数"
        print("我的练习页面：高数")
        #检查功能测试
        text=self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[4]/div/span").text
        assert text == "功能测试"
        print("我的练习页面：功能测试")
        #检查测试练习
        text=self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[5]/div/span").text
        assert text == "测试练习"
        print("我的练习页面：测试练习")
        #检查题库
        text=self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[7]/div/span").text
        assert text == "题库"
        print("我的练习页面：题库")
        print("我的练习页面元素正常........")

    # 功能测试
    def TestByExerciseFunction(self):
        #状态框选择正在进行，点击查询
        # self.driver.find_element(By.CSS_SELECTOR,"").send_keys()
        # self.driver.find_element(By.CSS_SELECTOR,"").click()
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(1) > div > div > div.ant-col.ant-form-item-control > div > div > div > div").click()
        sleep(1)
        #选择正在进行
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div/div/div[2]/div/div/div/div[1]/div").click()
        #点击查询
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(2) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(2) > button").click()

        #111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
        #状态框选择已完成，点击查询
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(1) > div > div > div.ant-col.ant-form-item-control > div > div > div > div").click()
        #点击已完成
        sleep(1)
        self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div/div/div[2]/div/div/div/div[2]/div").click()
        #点击查询
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(2) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(2) > button").click()
        #2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
        #点击重置
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(2) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(1) > button").click()
        print("我的练习页面：重置正常")
        #33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
        #点击删除
        sleep(1)
        #self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[6]/div/div[3]/a").click()
        #点击确定删除
        sleep(1)
        #self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div[2]/div/div[2]/div/div/div[2]/button[2]").click()
        print("我的练习页面：删除正常")
        #44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
        #点击二维码
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[6]/div/div[2]").click()
        #555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
        #点击高数，输入题库名称，点击查询，点击顺序练习
        #点击高数
        sleep(1)
        #self.driver.find_element(By.CSS_SELECTOR,"#rc-tabs-1-tab-高数 > span").click()
        self.driver.find_element(By.XPATH,
                                 "/html/body/div[1]/div/div/div/section/div/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[2]").click()
        #输入题库名称
        self.driver.find_element(By.CSS_SELECTOR,"#name").send_keys("高数")
        sleep(1)
        #点击查询
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(2) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(2) > button").click()
        #点击开始练习
        sleep(1)
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr/td[3]/div/div/a").click()
        #点击顺序练习
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "body > div:nth-child(9) > div > div.ant-modal-wrap > div > div.ant-modal-content > div > div > div.ant-card-body > div:nth-child(1) > div").click()
        sleep(1)
        self.driver.back()
        print("我的练习页面：顺序练习正常")
        #6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
        #点击高数，输入题库名称，点击查询，点击随机练习
        #点击高数
        sleep(1)
        #self.driver.find_element(By.CSS_SELECTOR,"#rc-tabs-1-tab-高数 > span").click()
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[2]").click()
        #输入题库名称
        self.driver.find_element(By.CSS_SELECTOR,"#name").send_keys("高数")
        sleep(1)
        #点击查询
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(2) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(2) > button").click()
        #点击开始练习
        sleep(1)
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr/td[3]/div/div/a").click()
        #点击随机练习
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "body > div:nth-child(9) > div > div.ant-modal-wrap > div > div.ant-modal-content > div > div > div.ant-card-body > div:nth-child(2) > div").click()
        sleep(1)
        self.driver.back()
        print("我的练习页面：随机练习正常")
        #7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
        #点击高数，输入题库名称，点击查询，点击错题练习
        #点击高数
        sleep(1)
        self.driver.find_element(By.XPATH,"/html/body/div[1]/div/div/div/section/div/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[2]").click()
        #输入题库名称
        self.driver.find_element(By.CSS_SELECTOR,"#name").send_keys("高数")
        sleep(1)
        #点击查询
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div.ant-pro-table > div.ant-pro-card.ant-pro-table-search.ant-pro-table-search-query-filter > form > div > div:nth-child(2) > div > div > div.ant-col.ant-form-item-control > div > div > div > div > div > div:nth-child(2) > button").click()
        #点击开始练习
        sleep(1)
        self.driver.find_element(By.XPATH, "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr/td[3]/div/div/a").click()
        #点击错题练习
        sleep(1)
        self.driver.find_element(By.CSS_SELECTOR, "body > div:nth-child(9) > div > div.ant-modal-wrap > div > div.ant-modal-content > div > div > div.ant-card-body > div:nth-child(3) > div").click()
        sleep(1)
        self.driver.back()
        print("我的练习页面：错题练习正常")
        print("我的练习页面全部正常...........")











#         self.driver.quit()
# exercise=WJExercise()
# exercise.TestByExercise()
# exercise.TestByExerciseFunction()
